<template>
	<view class="wanlshop-category-container" :style="{ '--bg': appStyle.home_nav_color }">
		<!-- 导航条 -->
		<view class="cu-custom" :style="{ height: $wanlshop.wanlsys().height + 'px',background: appStyle.home_nav_color}">
			<view class="cu-bar fixed solid-bottom navigator" :style="{
				height: $wanlshop.wanlsys().height + 'px',
				paddingTop: $wanlshop.wanlsys().top + 'px'
			}" style="width: 100%;">
	
				<text class="margin-left-bj text-bold" style="font-size: 36rpx;">分类</text>

				<view class="search-form round" style="flex: 1;">
					<text class="wlIcon-sousuo1"></text>
					<swiper class="search-swiper placeholder" vertical autoplay circular interval="3000">
						<swiper-item @tap="productSearch('')">搜索商品</swiper-item>
						<swiper-item v-for="(item, index) in common.modulesData.searchModules" :key="item.keywords"
							@tap="productSearch(item.keywords)">
							{{ item.keywords }}
						</swiper-item>
					</swiper>
				</view>
			</view>
		</view>

		<!-- 加载类目 -->
		<wanl-shop-classify :mainHeight="height" :categoryStyle="parseInt(common.appStyle.category_style)"
			:categoryData="categoryData" :adverData="common.adData.categoryAdverts" :color="appStyle.home_nav_color" />
		<!-- 模态框 -->
		<view class="WANL-MODAL">
			<view class="cu-modal top-modal" :class="modalName == 'menu' ? 'show' : ''" @tap="hideModal">
				<view class="wanl-modal-menu cu-dialog" @tap.stop="">
					<wanl-direct @change="hideModal" />
				</view>
			</view>
			<!-- 分享 -->
			<view class="cu-modal bottom-modal" :class="modalName == 'share' ? 'show' : ''" @tap="hideModal">
				<view class="cu-dialog" @tap.stop="">
					<wanl-share :scrollAnimation="scrollAnimation" shareTitle="我发现了一个很好的线上购物商城，这是商城类目"
						shareText="品质好而且很省钱如果自己在上面购买，每年可以省下1%~40%的钱" :image="$wanlshop.appstc('/common/logo.png')"
						:href="common.appConfig.domain + '/pages/category?QRtype=category'" @change="hideModal" />
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex';
	import wanlShopClassify from '@/components/wanl-shop/classify';
	export default {
		data() {
			return {
				height: 0,
				modalName: null,
				scrollAnimation: 300,
			};
		},
		components: {
			wanlShopClassify
		},
		computed: {
			...mapState(['common', 'statistics', 'cart']),
			categoryData() {
				// 剔除 公益领养 分类
				return this.common.modulesData.categoryModules.filter(item => {
					return item.name != '公益领养';
				})
			},
			// 全局样式
			appStyle() {
				let style = this.common.appStyle;
				uni.setNavigationBarColor({
					backgroundColor: style.home_nav_color
				});
				return style;
			}
		},
		onLoad() {
			let wanlsys = this.$wanlshop.wanlsys();
			// #ifdef APP-PLUS
			this.height = wanlsys.windowHeight + wanlsys.windowBottom - wanlsys.height;
			// #endif
			// #ifdef H5
			this.height = wanlsys.windowHeight + wanlsys.windowBottom - wanlsys.height - 50;
			// #endif
			// #ifdef MP
			setTimeout(() => {
				this.height = wanlsys.windowHeight - wanlsys.height;
				console.log('wanlsys.windowHeight', wanlsys.windowHeight);
				console.log('wanlsys.height', wanlsys.height);
				console.log('mainHeight', this.height);
			}, 300)
			// #endif
			// #ifdef MP-WEIXIN
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
			});
			// #endif
		},
		onPullDownRefresh() {
			this.getServices();
			console.log(1);
		},
		methods: {
			...mapActions({
				getServices: 'common/getServices'
			}),
			// 弹出层
			showModal(name) {
				// 滚动下分享
				if (name == 'share' && this.modalName != 'share') {
					setTimeout(() => {
						this.scrollAnimation = 300;
					}, 300);
				}
				this.modalName = name;
			},
			hideModal(name) {
				if (name) {
					this.showModal(name);
				} else {
					this.modalName = null;
				}
			},
			handleGroups() {
				this.$wanlshop.to('/pages/apps/groups/index');
			},
			productSearch(text) {
				this.$wanlshop.to(`/pages/page/search?type=goods&keywords=${text}`, 'fade-in', 100);
			}
		}
	};
</script>

<style>
	.wanlshop-category-container {
		background-color: var(--bg);
	}

	.navigator {
		box-sizing: border-box;
		/* #ifdef MP */
		padding-right: 220rpx;
		/* #endif */
	}

	.cu-custom .cu-bar {
		z-index: 99;
	}

	.cu-bar .action {
		position: relative;
	}

	/* #ifdef MP */
	.cu-bar .search-form {
		margin: 0 0 0 25rpx;
	}

	/* #endif */
</style>